import 'package:flutter/material.dart';
import '../constants/app_colors.dart';
import '../models/diary.dart';
import '../utils/date_util.dart';
import 'package:google_fonts/google_fonts.dart';

class DiaryDetailScreen extends StatelessWidget {
  final Diary diary;

  const DiaryDetailScreen({
    Key? key,
    required this.diary,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final date = DateUtil.parseDate(diary.date);
    final dateStr = DateUtil.formatDateChinese(date);
    
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        centerTitle: true,
        title: Text(
          '日记详情',
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 24,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 日期和时间
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  dateStr,
                  style: Theme.of(context).textTheme.titleLarge?.copyWith(
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Text(
                  diary.createdAt.substring(11, 16), // 只显示时:分
                  style: Theme.of(context).textTheme.bodyMedium,
                ),
              ],
            ),
            const Divider(height: 24),
            
            // 日记内容
            Text(
              diary.content,
              style: Theme.of(context).textTheme.bodyLarge,
            ),
            
            // 标签
            if (diary.tags != null && diary.tags!.isNotEmpty) ...[
              const SizedBox(height: 24),
              const Divider(height: 1),
              const SizedBox(height: 16),
              Text(
                '标签',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              const SizedBox(height: 8),
              Wrap(
                spacing: 8,
                runSpacing: 8,
                children: diary.tags!.map((tag) {
                  return _buildTagChip(tag, context);
                }).toList(),
              ),
            ],
          ],
        ),
      ),
    );
  }

  Widget _buildTagChip(MoodTag tag, BuildContext context) {
    final color = AppColors.getTagCategoryColor(tag.category);
    
    return Chip(
      label: Text(
        tag.name,
        style: TextStyle(
          color: color,
        ),
      ),
      backgroundColor: color.withOpacity(0.1),
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
    );
  }
}